home *** CD-ROM | disk | FTP | other *** search
/ Risc World 5 / Risc World 5.iso / SOFTWARE / Issue3 / Games / xrick / !xrick / src / c / scr_getnam < prev    next >
Text File  |  2004-06-24  |  5KB  |  276 lines

  1. /*
  2.  * xrick/src/scr_getname.c
  3.  *
  4.  * Copyright (C) 1998-2002 BigOrno (bigorno@bigorno.net). All rights reserved.
  5.  *
  6.  * The use and distribution terms for this software are contained in the file
  7.  * named README, which can be found in the root of this distribution. By
  8.  * using this software in any fashion, you are agreeing to be bound by the
  9.  * terms of this license.
  10.  *
  11.  * You must not remove this notice, or any other, from this software.
  12.  */
  13.  
  14. #include "system.h"
  15. #include "game.h"
  16. #include "screens.h"
  17.  
  18. #include "draw.h"
  19. #include "control.h"
  20.  
  21. /*
  22.  * local vars
  23.  */
  24. static U8 seq = 0;
  25. static U8 x, y, p;
  26. static U8 name[10];
  27.  
  28. #define TILE_POINTER '\072'
  29. #define TILE_CURSOR '\073'
  30. #define TOPLEFT_X 116
  31. #define TOPLEFT_Y 64
  32. #define NAMEPOS_X 120
  33. #define NAMEPOS_Y 160
  34. #define AUTOREPEAT_TMOUT 100
  35.  
  36.  
  37. /*
  38.  * prototypes
  39.  */
  40. static void pointer_show(U8);
  41. static void name_update(void);
  42. static void name_draw(void);
  43.  
  44.  
  45. /*
  46.  * Get name
  47.  *
  48.  * return: 0 while running, 1 when finished.
  49.  */
  50. U8
  51. screen_getname(void)
  52. {
  53.   static U32 tm = 0;
  54.   U8 i, j;
  55.  
  56.   if (seq == 0) {
  57.     /* figure out if this is a high score */
  58.     if (game_score < game_hscores[7].score)
  59.       return SCREEN_DONE;
  60.  
  61.     /* prepare */
  62.     draw_tilesBank = 0;
  63. #ifdef GFXPC
  64.     draw_filter = 0xffff;
  65. #endif
  66.     for (i = 0; i < 10; i++)
  67.       name[i] = '@';
  68.     x = y = p = 0;
  69.     game_rects = &draw_SCREENRECT;
  70.     seq = 1;
  71.   }
  72.  
  73.   switch (seq) {
  74.   case 1:  /* prepare screen */
  75.     sysvid_clear();
  76. #ifdef GFXPC
  77.     draw_setfb(32, 8);
  78.     draw_filter = 0xaaaa; /* red */
  79.     draw_tilesListImm(screen_congrats);
  80. #endif
  81.     draw_setfb(76, 40);
  82. #ifdef GFXPC
  83.     draw_filter = 0xffff; /* yellow */
  84. #endif
  85.     draw_tilesListImm((U8 *)"PLEASE@ENTER@YOUR@NAME\376");
  86. #ifdef GFXPC
  87.     draw_filter = 0x5555; /* green */
  88. #endif
  89.     for (i = 0; i < 6; i++)
  90.       for (j = 0; j < 4; j++) {
  91.     draw_setfb(TOPLEFT_X + i * 8 * 2, TOPLEFT_Y + j * 8 * 2);
  92.     draw_tile('A' + i + j * 6);
  93.       }
  94.     draw_setfb(TOPLEFT_X, TOPLEFT_Y + 64);
  95. #ifdef GFXST
  96.     draw_tilesListImm((U8 *)"Y@Z@.@@@\074\373\374\375\376");
  97. #endif
  98. #ifdef GFXPC
  99.     draw_tilesListImm((U8 *)"Y@Z@.@@@\074@\075@\376");
  100. #endif
  101.     name_draw();
  102.     pointer_show(TRUE);
  103.     seq = 2;
  104.     break;
  105.  
  106.   case 2:  /* wait for key pressed */
  107.     if (control_status & CONTROL_FIRE)
  108.       seq = 3;
  109.     if (control_status & CONTROL_UP) {
  110.       if (y > 0) {
  111.     pointer_show(FALSE);
  112.     y--;
  113.     pointer_show(TRUE);
  114.     tm = sys_gettime();
  115.       }
  116.       seq = 4;
  117.     }
  118.     if (control_status & CONTROL_DOWN) {
  119.       if (y < 4) {
  120.     pointer_show(FALSE);
  121.     y++;
  122.     pointer_show(TRUE);
  123.     tm = sys_gettime();
  124.       }
  125.       seq = 5;
  126.     }
  127.     if (control_status & CONTROL_LEFT) {
  128.       if (x > 0) {
  129.     pointer_show(FALSE);
  130.     x--;
  131.     pointer_show(TRUE);
  132.     tm = sys_gettime();
  133.       }
  134.       seq = 6;
  135.     }
  136.     if (control_status & CONTROL_RIGHT) {
  137.       if (x < 5) {
  138.     pointer_show(FALSE);
  139.     x++;
  140.     pointer_show(TRUE);
  141.     tm = sys_gettime();
  142.       }
  143.       seq = 7;
  144.     }
  145.     if (seq == 2)
  146.       sys_sleep(50);
  147.     break;
  148.  
  149.   case 3:  /* wait for FIRE released */
  150.     if (!(control_status & CONTROL_FIRE)) {
  151.       if (x == 5 && y == 4) {  /* end */
  152.     i = 0;
  153.     while (game_score < game_hscores[i].score)
  154.       i++;
  155.     j = 7;
  156.     while (j > i) {
  157.       game_hscores[j].score = game_hscores[j - 1].score;
  158.       for (x = 0; x < 10; x++)
  159.         game_hscores[j].name[x] = game_hscores[j - 1].name[x];
  160.       j--;
  161.     }
  162.     game_hscores[i].score = game_score;
  163.     for (x = 0; x < 10; x++)
  164.       game_hscores[i].name[x] = name[x];
  165.     seq = 99;
  166.       }
  167.       else {
  168.     name_update();
  169.     name_draw();
  170.     seq = 2;
  171.       }
  172.     }
  173.     else
  174.       sys_sleep(50);
  175.     break;
  176.  
  177.   case 4:  /* wait for UP released */
  178.     if (!(control_status & CONTROL_UP) ||
  179.     sys_gettime() - tm > AUTOREPEAT_TMOUT)
  180.       seq = 2;
  181.     else
  182.       sys_sleep(50);
  183.     break;
  184.  
  185.   case 5:  /* wait for DOWN released */
  186.     if (!(control_status & CONTROL_DOWN) ||
  187.     sys_gettime() - tm > AUTOREPEAT_TMOUT)
  188.       seq = 2;
  189.     else
  190.       sys_sleep(50);
  191.     break;
  192.  
  193.   case 6:  /* wait for LEFT released */
  194.     if (!(control_status & CONTROL_LEFT) ||
  195.     sys_gettime() - tm > AUTOREPEAT_TMOUT)
  196.       seq = 2;
  197.     else
  198.       sys_sleep(50);
  199.     break;
  200.  
  201.   case 7:  /* wait for RIGHT released */
  202.     if (!(control_status & CONTROL_RIGHT) ||
  203.     sys_gettime() - tm > AUTOREPEAT_TMOUT)
  204.       seq = 2;
  205.     else
  206.       sys_sleep(50);
  207.     break;
  208.  
  209.   }
  210.  
  211.   if (control_status & CONTROL_EXIT)  /* check for exit request */
  212.     return SCREEN_EXIT;
  213.  
  214.   if (seq == 99) {  /* seq 99, we're done */
  215.     sysvid_clear();
  216.     seq = 0;
  217.     return SCREEN_DONE;
  218.   }
  219.   else
  220.     return SCREEN_RUNNING;
  221. }
  222.  
  223.  
  224. static void
  225. pointer_show(U8 show)
  226. {
  227.   draw_setfb(TOPLEFT_X + x * 8 * 2, TOPLEFT_Y + y * 8 * 2 + 8);
  228. #ifdef GFXPC
  229.   draw_filter = 0xaaaa; /* red */
  230. #endif
  231.   draw_tile((show == TRUE)?TILE_POINTER:'@');
  232. }
  233.  
  234. static void
  235. name_update(void)
  236. {
  237.   U8 i;
  238.  
  239.   i = x + y * 6;
  240.   if (i < 26 && p < 10)
  241.     name[p++] = 'A' + i;
  242.   if (i == 26 && p < 10)
  243.     name[p++] = '.';
  244.   if (i == 27 && p < 10)
  245.     name[p++] = '@';
  246.   if (i == 28 && p > 0) {
  247.     p--;
  248.   }
  249. }
  250.  
  251. static void
  252. name_draw(void)
  253. {
  254.   U8 i;
  255.  
  256.   draw_setfb(NAMEPOS_X, NAMEPOS_Y);
  257. #ifdef GFXPC
  258.   draw_filter = 0xaaaa; /* red */
  259. #endif
  260.   for (i = 0; i < p; i++)
  261.     draw_tile(name[i]);
  262.   for (i = p; i < 10; i++)
  263.     draw_tile(TILE_CURSOR);
  264.  
  265. #ifdef GFXST
  266.   draw_setfb(NAMEPOS_X, NAMEPOS_Y + 8);
  267.   for (i = 0; i < 10; i++)
  268.     draw_tile('@');
  269.   draw_setfb(NAMEPOS_X + 8 * (p < 9 ? p : 9), NAMEPOS_Y + 8);
  270.   draw_tile(TILE_POINTER);
  271. #endif
  272. }
  273.  
  274.  
  275. /* eof */
  276.